package com.bw.liveplay.common.mvvm.viewmodel

import android.view.View
import android.widget.Button
import com.bw.liveplay.BR
import com.bw.liveplay.R
import com.bw.liveplay.common.entity.BaseEntity
import com.bw.liveplay.common.entity.RecommentEntity
import com.bw.liveplay.common.mvvm.adapter.RecommentAdapter
import com.bw.liveplay.common.mvvm.mondel.TagListModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemChildClickListener
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * @author KK
 * @description:
 * @date :2021/11/12 10:09
 *
 */
class RecommentViewModel : BaseViewModel<TagListModel>(),OnItemChildClickListener{
     var adapter : RecommentAdapter = RecommentAdapter()
    var flag = false
    override fun result(t: BaseEntity) {
        if(t is RecommentEntity){
            var t  = t as RecommentEntity
            adapter.setNewInstance(t.data!!.data)
        }
    }

    override fun initData() {
        adapter.setOnItemChildClickListener(this)
        m.requestTagList(0,10,0,"all",1)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(this)
    }

    override fun onItemChildClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        var btn = view.findViewById<Button>(R.id.item_recomment_gz)
        when(view.id){
            R.id.item_recomment_gz->{
                if(flag){
                    btn.setText("关注")
                    flag=false
                }else{
                    btn.setText("已关注")
                    flag=true
                }
            }
        }
    }
}